<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet"  th:href = "@{/plugins/xcConfirm/xcConfirm.css}">
    <script th:src = "@{/plugins/xcConfirm/xcConfirm.js}"></script>
    <script>
        function getUrlParms(name){
            //获得页面url的某个url参数的方法
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)
                return unescape(r[2]);
            return null;
        }
        var id = getUrlParms("rslt");
        // console.log(id);
        if(id=="1"){
            $(function () {
                var txt=  "修改失败";
                // console.log(txt);
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
            })
        }
    </script>

</head>
<body>
<div class="row" >
    <br>
    <br>
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <form class="form-horizontal"  th:action ="@{/admin/updateTag}" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label  class="col-sm-2 control-label">标签名称</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="tag" placeholder="请输入内容" th:value="${tag.tag}">
                    <input type="text" class="form-control" name="id" style="display: none" th:value="${tag.id}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">标签封面</label>
                <div class="col-sm-10">
                    <a href="javascript:void(0)"  onclick="uploadPhoto()">
                        <img th:src="${tag.tagphoto}"  width="100px"
                             id="img-show">
                    </a>
                    <br>
                    <input name="photo" id="img-upload"  type="file"/>
                </div>
            </div>

            <div class="form-group ">
                <div class="col-sm-offset-2 col-sm-10 pull-right">
                    <button type="button" class="btn btn-warning"  onclick="window.history.go(-1)">返回</button>
                    <button type="submit" class="btn btn-info">提交</button>

                </div>
            </div>
        </form>
    </div>
    <div class="col-md-1"></div>
</div>
<!--图片上传-->
<script type="text/javascript">
    $('#img-upload').change(function(e){
        var input = $("#img-upload");
        var file = input[0].files[0];//获取input上传的文件
        if(!file.name){
            $(function () {
                var txt=  "未选择图片";
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.warning);
            })
        }else{
            //高版本浏览器对文件上传路径进行了安全处理，无法直接通过获取input的value进行访问，故转化为获取图片的url进行安全访问
            var url = window.URL.createObjectURL(file);//将上传的文件转化为url
            $("#img-show").attr('src', url);//更新img的src属性
        };
    });
</script>

</body>
</html>